package com.sf.fy.uav.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sf.fy.uav.common.awt.JwtUtil;
import com.sf.fy.uav.common.request.user.UserExtraRequest;
import com.sf.fy.uav.common.response.user.UserExtraResponse;
import com.sf.fy.uav.common.utils.BeanUtil;
import com.sf.fy.uav.user.entity.UserExtra;
import com.sf.fy.uav.user.mapper.UserExtraMapper;
import com.sf.fy.uav.user.service.IUserExtraService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户额外信息表 服务实现类
 * </p>
 *
 * @author LTQ
 * @since 2023-06-14
 */
@Service
public class UserExtraServiceImpl extends ServiceImpl<UserExtraMapper, UserExtra> implements IUserExtraService {
    @Autowired
    private UserExtraMapper userExtraMapper;

    @Override
    public void add(UserExtraRequest userExtraRequest) {
        UserExtra userExtra = BeanUtil.copyProperties(userExtraRequest, UserExtra.class);
        userExtraMapper.insert(userExtra);
    }

    @Override
    public void edit(UserExtraRequest userExtraRequest) {
        UserExtra userExtra = BeanUtil.copyProperties(userExtraRequest, UserExtra.class);
        userExtraMapper.updateById(userExtra);
    }

    @Override
    public UserExtraResponse getById(String id) {
        UserExtra userExtra = userExtraMapper.selectById(id);
        return BeanUtil.copyProperties(userExtra, UserExtraResponse.class);
    }

    @Override
    public UserExtra getByUserId(String userId) {
        QueryWrapper<UserExtra> userExtraQueryWrapper = new QueryWrapper<>();
        userExtraQueryWrapper.eq("user_id", userId);
        return userExtraMapper.selectOne(userExtraQueryWrapper);
    }
}
